const util = require("../../../utils/util");
Page({

      /**
       * 页面的初始数据
       */
      data: {
            map: { // 详情页的地图参数
                  longitude: '113.238478',
                  latitude: '23.403277',
                  markers: [{
                        id: '开始',
                        longitude: '113.218178',
                        latitude: '23.403177',
                        zIndex: true,
                        // callout: {
                        //       content: " 厦门思明区政府 \n 12000元/㎡",
                        //       padding: 10,
                        //       display: 'BYCLICK',
                        //       textAlign: 'center',
                        // },
                        // label: {
                        //       content: '厦门思明区政府',
                        //       textAlign: 'center',
                        // }
                  }]
            },
            // 物流时间线
            BillTrace: [],
      },

      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
            console.log(options)

            this.ajaxBillTrace('JDVC07055947847')
      },
      /* 请求时间线数据 */
      ajaxBillTrace(WaybillCode) {
            let ajaxData = {
                  // WaybillCode: 'JDVC07129657515'
                  WaybillCode: WaybillCode
            }
            let ajaxObj = {
                  // url: 'http://192.168.30.217:8073/api/Ems/JD/WayBill/BillTrace',
                  url: 'http://api2.exmsg.net:11811//api/Ems/JD/WayBill/BillTrace',
                  method: 'get',
                  complete: res => {
                        console.log(res)
                        // console.log(res.data.data)
                        let this_ = this;
                        let data = res.data.data
                        if (res.data.success) {
                              data = JSON.parse(data);
                              let Body = JSON.parse(data['Body'])
                              if (Body) {
                                    let bodyData = Body['jingdong_ldop_receive_trace_get_responce']['querytrace_result']['data']
                                    if (bodyData instanceof Array) {
                                          bodyData.reverse();
                                          bodyData.forEach(function (item) {
                                                item.opeRemark = this_.phoneCall(item.opeRemark)
                                          })

                                          this.setData({
                                                BillTrace: bodyData
                                          })
                                    }
                              }
                        }
                  }
            }
            util.$ajax(ajaxData, ajaxObj)
      },

      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function () {
            var mapCtx = wx.createMapContext("map");
            this.mapCtx = mapCtx;
            this.includePoints([{
                  latitude: 23.403177,
                  longitude: 113.218178
            }, {
                  latitude: 23.403277,
                  longitude: 113.238478
            }])
      },

      /* 设置包含所有标记点：缩放视野以包含所有给定的坐标点 */
      includePoints(points) {
            this.mapCtx.includePoints({
                  padding: [70, 70, 70, 70],
                  points: points
            })
      },


      /* 给电话高亮 */
      phoneCall(data) {
            // var flag = new RegExp('1[3456789]\d{9}', 'g').test(data)
            if (/1[3456789]\d{9}/g.test(data)) {
                  // flag = new RegExp('1[3456789]\d{9}', 'g')  <span class="color4">2</span>
                  var phones = data.match(/1[3456789]\d{9}/g)
                  phones.forEach(function (item) {
                        data = data.replace(item, ' <span class="color7" catchtap="callPhone">' + item + '</span>')
                  })
                  console.log('data')
                  console.log(data)
            }
            return data;
      },
      callPhone(e){
            console.log('djfoe')
            console.log(e)
      },

      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {

      },

      /**
       * 生命周期函数--监听页面隐藏
       */
      onHide: function () {

      },

      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function () {

      },

      /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function () {

      },

      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {

      },

      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function () {

      }
})